/*
* Copyright (C) 1997-2001 Id Software, Inc.
* 
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.
* 
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*  
*/

// Created on 04.11.2003 by RST.
// $Id: edict_t.java,v 1.7 2005/02/19 21:17:44 salomo Exp $
using System;
using Suake2.UI;
using Com = Suake2.UI.qcommon.Com;
using Suake2.UI.util;
namespace Suake2.UI.game
{
	
	public class edict_t
	{
		private void  InitBlock()
		{
			s = new entity_state_t(this);
			area = new link_t(this);
			clusternums = new int[Defines.MAX_ENT_CLUSTERS];
		}
		
		/// <summary>Constructor. </summary>
		public edict_t(int i)
		{
			InitBlock();
			s.number = i;
			index = i;
		}
		
		/// <summary>Used during level loading. </summary>
		public virtual void  cleararealinks()
		{
			area = new link_t(this);
		}
		
		/// <summary>Integrated entity state. </summary>
		//UPGRADE_NOTE: The initialization of  's' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		public entity_state_t s;
		
		public bool inuse;
		
		public int linkcount;
		
		/// <summary> FIXME: move these fields to a server private sv_entity_t. linked to a
		/// division node or leaf.
		/// </summary>
		//UPGRADE_NOTE: The initialization of  'area' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		public link_t area;
		
		/// <summary>if -1, use headnode instead. </summary>
		public int num_clusters;
		
		//UPGRADE_NOTE: The initialization of  'clusternums' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		public int[] clusternums;
		
		/// <summary>unused if num_clusters != -1. </summary>
		public int headnode;
		
		public int areanum, areanum2;
		
		//================================
		
		/// <summary>SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc. </summary>
		public int svflags;
		
		public float[] mins = new float[]{0, 0, 0};
		
		public float[] maxs = new float[]{0, 0, 0};
		
		public float[] absmin = new float[]{0, 0, 0};
		
		public float[] absmax = new float[]{0, 0, 0};
		
		public float[] size = new float[]{0, 0, 0};
		
		public int solid;
		
		public int clipmask;
		
		//================================
		public int movetype;
		
		public int flags;
		
		public System.String model = null;
		
		/// <summary>sv.time when the object was freed. </summary>
		public float freetime;
		
		//
		// only used locally in game, not by server
		//
		public System.String message = null;
		
		public System.String classname = "";
		
		public int spawnflags;
		
		public float timestamp;
		
		/// <summary>set in qe3, -1 = up, -2 = down </summary>
		public float angle;
		
		public System.String target = null;
		
		public System.String targetname = null;
		
		public System.String killtarget = null;
		
		public System.String team = null;
		
		public System.String pathtarget = null;
		
		public System.String deathtarget = null;
		
		public System.String combattarget = null;
		
		public edict_t target_ent = null;
		
		public float speed, accel, decel;
		
		public float[] movedir = new float[]{0, 0, 0};
		
		public float[] pos1 = new float[]{0, 0, 0};
		
		public float[] pos2 = new float[]{0, 0, 0};
		
		public float[] velocity = new float[]{0, 0, 0};
		
		public float[] avelocity = new float[]{0, 0, 0};
		
		public int mass;
		
		public float air_finished;
		
		/// <summary>per entity gravity multiplier (1.0 is normal). </summary>
		public float gravity;
		
		/// <summary>use for lowgrav artifact, flares. </summary>
		
		public edict_t goalentity = null;
		
		public edict_t movetarget = null;
		
		public float yaw_speed;
		
		public float ideal_yaw;
		
		public float nextthink;
		
		public EntThinkAdapter prethink = null;
		
		public EntThinkAdapter think = null;
		
		public EntBlockedAdapter blocked = null;
		
		public EntTouchAdapter touch = null;
		
		public EntUseAdapter use = null;
		
		public EntPainAdapter pain = null;
		
		public EntDieAdapter die = null;
		
		/// <summary>Are all these legit? do we need more/less of them? </summary>
		public float touch_debounce_time;
		
		public float pain_debounce_time;
		
		public float damage_debounce_time;
		
		/// <summary>Move to clientinfo. </summary>
		public float fly_sound_debounce_time;
		
		public float last_move_time;
		
		public int health;
		
		public int max_health;
		
		public int gib_health;
		
		public int deadflag;
		
		public int show_hostile;
		
		public float powerarmor_time;
		
		/// <summary>target_changelevel. </summary>
		public System.String map = null;
		
		/// <summary>Height above origin where eyesight is determined. </summary>
		public int viewheight;
		
		public int takedamage;
		
		public int dmg;
		
		public int radius_dmg;
		
		public float dmg_radius;
		
		/// <summary>make this a spawntemp var? </summary>
		public int sounds;
		
		public int count;
		
		public edict_t chain = null;
		
		public edict_t enemy = null;
		
		public edict_t oldenemy = null;
		
		public edict_t activator = null;
		
		public edict_t groundentity = null;
		
		public int groundentity_linkcount;
		
		public edict_t teamchain = null;
		
		public edict_t teammaster = null;
		
		/// <summary>can go in client only. </summary>
		public edict_t mynoise = null;
		
		public edict_t mynoise2 = null;
		
		public int noise_index;
		
		public int noise_index2;
		
		public float volume;
		
		public float attenuation;
		
		/// <summary>Timing variables. </summary>
		public float wait;
		
		/// <summary>before firing targets... </summary>
		public float delay;
		
		public float random;
		
		public float teleport_time;
		
		public int watertype;
		
		public int waterlevel;
		
		public float[] move_origin = new float[]{0, 0, 0};
		
		public float[] move_angles = new float[]{0, 0, 0};
		
		/// <summary>move this to clientinfo? . </summary>
		public int light_level;
		
		/// <summary>also used as areaportal number. </summary>
		public int style;
		
		public gitem_t item; // for bonus items
		
		/// <summary>common integrated data blocks. </summary>
		public moveinfo_t moveinfo = new moveinfo_t();
		
		public monsterinfo_t monsterinfo = new monsterinfo_t();
		
		public gclient_t client;
		
		public edict_t owner;
		
		/// <summary>Introduced by rst. </summary>
		public int index;
		
		/////////////////////////////////////////////////
		
		public virtual bool setField(System.String key, System.String value_Renamed)
		{
			
			if (key.Equals("classname"))
			{
				classname = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("model"))
			{
				model = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("spawnflags"))
			{
				spawnflags = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("speed"))
			{
				speed = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("accel"))
			{
				accel = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("decel"))
			{
				decel = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("target"))
			{
				target = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("targetname"))
			{
				targetname = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("pathtarget"))
			{
				pathtarget = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("deathtarget"))
			{
				deathtarget = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			if (key.Equals("killtarget"))
			{
				killtarget = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("combattarget"))
			{
				combattarget = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("message"))
			{
				message = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("team"))
			{
				team = GameSpawn.ED_NewString(value_Renamed);
				Com.dprintln("Monster Team:" + team);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("wait"))
			{
				wait = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("delay"))
			{
				delay = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("random"))
			{
				random = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("move_origin"))
			{
				move_origin = Lib.atov(value_Renamed);
				return true;
			} // F_VECTOR),
			
			if (key.Equals("move_angles"))
			{
				move_angles = Lib.atov(value_Renamed);
				return true;
			} // F_VECTOR),
			
			if (key.Equals("style"))
			{
				style = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("count"))
			{
				count = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("health"))
			{
				health = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("sounds"))
			{
				sounds = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("light"))
			{
				return true;
			} // F_IGNORE),
			
			if (key.Equals("dmg"))
			{
				dmg = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("mass"))
			{
				mass = Lib.atoi(value_Renamed);
				return true;
			} // F_INT),
			
			if (key.Equals("volume"))
			{
				volume = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("attenuation"))
			{
				attenuation = Lib.atof(value_Renamed);
				return true;
			} // F_FLOAT),
			
			if (key.Equals("map"))
			{
				map = GameSpawn.ED_NewString(value_Renamed);
				return true;
			} // F_LSTRING),
			
			if (key.Equals("origin"))
			{
				s.origin = Lib.atov(value_Renamed);
				return true;
			} // F_VECTOR),
			
			if (key.Equals("angles"))
			{
				s.angles = Lib.atov(value_Renamed);
				return true;
			} // F_VECTOR),
			
			if (key.Equals("angle"))
			{
				s.angles = new float[]{0, Lib.atof(value_Renamed), 0};
				return true;
			} // F_ANGLEHACK),
			
			if (key.Equals("item"))
			{
				GameBase.gi.error("ent.set(\"item\") called.");
				return true;
			} // F_ITEM)
			
			return false;
		}
		
		/// <summary>Writes the entity to the file. </summary>
		public virtual void  write(QuakeFile f)
		{
			
			s.write(f);
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Boolean) inuse);
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int32) linkcount);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Int32) num_clusters);
			
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Int32) 9999);
			
			if (clusternums == null)
			{
				System.IO.BinaryWriter temp_BinaryWriter5;
				temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter5.Write((System.Int32) (- 1));
			}
			else
			{
				System.IO.BinaryWriter temp_BinaryWriter6;
				temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter6.Write((System.Int32) Defines.MAX_ENT_CLUSTERS);
				for (int n = 0; n < Defines.MAX_ENT_CLUSTERS; n++)
				{
					System.IO.BinaryWriter temp_BinaryWriter7;
					temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
					temp_BinaryWriter7.Write((System.Int32) clusternums[n]);
				}
			}
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Int32) headnode);
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Int32) areanum);
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Int32) areanum2);
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Int32) svflags);
			f.writeVector(mins);
			f.writeVector(maxs);
			f.writeVector(absmin);
			f.writeVector(absmax);
			f.writeVector(size);
			System.IO.BinaryWriter temp_BinaryWriter12;
			temp_BinaryWriter12 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter12.Write((System.Int32) solid);
			System.IO.BinaryWriter temp_BinaryWriter13;
			temp_BinaryWriter13 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter13.Write((System.Int32) clipmask);
			
			System.IO.BinaryWriter temp_BinaryWriter14;
			temp_BinaryWriter14 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter14.Write((System.Int32) movetype);
			System.IO.BinaryWriter temp_BinaryWriter15;
			temp_BinaryWriter15 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter15.Write((System.Int32) flags);
			
			f.writeString(model);
			System.IO.BinaryWriter temp_BinaryWriter16;
			temp_BinaryWriter16 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter16.Write((System.Single) freetime);
			f.writeString(message);
			f.writeString(classname);
			System.IO.BinaryWriter temp_BinaryWriter17;
			temp_BinaryWriter17 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter17.Write((System.Int32) spawnflags);
			System.IO.BinaryWriter temp_BinaryWriter18;
			temp_BinaryWriter18 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter18.Write((System.Single) timestamp);
			
			System.IO.BinaryWriter temp_BinaryWriter19;
			temp_BinaryWriter19 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter19.Write((System.Single) angle);
			
			f.writeString(target);
			f.writeString(targetname);
			f.writeString(killtarget);
			f.writeString(team);
			f.writeString(pathtarget);
			f.writeString(deathtarget);
			f.writeString(combattarget);
			
			f.writeEdictRef(target_ent);
			
			System.IO.BinaryWriter temp_BinaryWriter20;
			temp_BinaryWriter20 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter20.Write((System.Single) speed);
			System.IO.BinaryWriter temp_BinaryWriter21;
			temp_BinaryWriter21 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter21.Write((System.Single) accel);
			System.IO.BinaryWriter temp_BinaryWriter22;
			temp_BinaryWriter22 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter22.Write((System.Single) decel);
			
			f.writeVector(movedir);
			
			f.writeVector(pos1);
			f.writeVector(pos2);
			
			f.writeVector(velocity);
			f.writeVector(avelocity);
			
			System.IO.BinaryWriter temp_BinaryWriter23;
			temp_BinaryWriter23 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter23.Write((System.Int32) mass);
			System.IO.BinaryWriter temp_BinaryWriter24;
			temp_BinaryWriter24 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter24.Write((System.Single) air_finished);
			
			System.IO.BinaryWriter temp_BinaryWriter25;
			temp_BinaryWriter25 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter25.Write((System.Single) gravity);
			
			f.writeEdictRef(goalentity);
			f.writeEdictRef(movetarget);
			
			System.IO.BinaryWriter temp_BinaryWriter26;
			temp_BinaryWriter26 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter26.Write((System.Single) yaw_speed);
			System.IO.BinaryWriter temp_BinaryWriter27;
			temp_BinaryWriter27 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter27.Write((System.Single) ideal_yaw);
			
			System.IO.BinaryWriter temp_BinaryWriter28;
			temp_BinaryWriter28 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter28.Write((System.Single) nextthink);
			
			f.writeAdapter(prethink);
			f.writeAdapter(think);
			f.writeAdapter(blocked);
			
			f.writeAdapter(touch);
			f.writeAdapter(use);
			f.writeAdapter(pain);
			f.writeAdapter(die);
			
			System.IO.BinaryWriter temp_BinaryWriter29;
			temp_BinaryWriter29 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter29.Write((System.Single) touch_debounce_time);
			System.IO.BinaryWriter temp_BinaryWriter30;
			temp_BinaryWriter30 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter30.Write((System.Single) pain_debounce_time);
			System.IO.BinaryWriter temp_BinaryWriter31;
			temp_BinaryWriter31 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter31.Write((System.Single) damage_debounce_time);
			
			System.IO.BinaryWriter temp_BinaryWriter32;
			temp_BinaryWriter32 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter32.Write((System.Single) fly_sound_debounce_time);
			System.IO.BinaryWriter temp_BinaryWriter33;
			temp_BinaryWriter33 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter33.Write((System.Single) last_move_time);
			
			System.IO.BinaryWriter temp_BinaryWriter34;
			temp_BinaryWriter34 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter34.Write((System.Int32) health);
			System.IO.BinaryWriter temp_BinaryWriter35;
			temp_BinaryWriter35 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter35.Write((System.Int32) max_health);
			
			System.IO.BinaryWriter temp_BinaryWriter36;
			temp_BinaryWriter36 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter36.Write((System.Int32) gib_health);
			System.IO.BinaryWriter temp_BinaryWriter37;
			temp_BinaryWriter37 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter37.Write((System.Int32) deadflag);
			System.IO.BinaryWriter temp_BinaryWriter38;
			temp_BinaryWriter38 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter38.Write((System.Int32) show_hostile);
			
			System.IO.BinaryWriter temp_BinaryWriter39;
			temp_BinaryWriter39 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter39.Write((System.Single) powerarmor_time);
			
			f.writeString(map);
			
			System.IO.BinaryWriter temp_BinaryWriter40;
			temp_BinaryWriter40 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter40.Write((System.Int32) viewheight);
			System.IO.BinaryWriter temp_BinaryWriter41;
			temp_BinaryWriter41 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter41.Write((System.Int32) takedamage);
			System.IO.BinaryWriter temp_BinaryWriter42;
			temp_BinaryWriter42 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter42.Write((System.Int32) dmg);
			System.IO.BinaryWriter temp_BinaryWriter43;
			temp_BinaryWriter43 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter43.Write((System.Int32) radius_dmg);
			System.IO.BinaryWriter temp_BinaryWriter44;
			temp_BinaryWriter44 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter44.Write((System.Single) dmg_radius);
			
			System.IO.BinaryWriter temp_BinaryWriter45;
			temp_BinaryWriter45 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter45.Write((System.Int32) sounds);
			System.IO.BinaryWriter temp_BinaryWriter46;
			temp_BinaryWriter46 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter46.Write((System.Int32) count);
			
			f.writeEdictRef(chain);
			f.writeEdictRef(enemy);
			f.writeEdictRef(oldenemy);
			f.writeEdictRef(activator);
			f.writeEdictRef(groundentity);
			System.IO.BinaryWriter temp_BinaryWriter47;
			temp_BinaryWriter47 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter47.Write((System.Int32) groundentity_linkcount);
			f.writeEdictRef(teamchain);
			f.writeEdictRef(teammaster);
			
			f.writeEdictRef(mynoise);
			f.writeEdictRef(mynoise2);
			
			System.IO.BinaryWriter temp_BinaryWriter48;
			temp_BinaryWriter48 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter48.Write((System.Int32) noise_index);
			System.IO.BinaryWriter temp_BinaryWriter49;
			temp_BinaryWriter49 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter49.Write((System.Int32) noise_index2);
			
			System.IO.BinaryWriter temp_BinaryWriter50;
			temp_BinaryWriter50 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter50.Write((System.Single) volume);
			System.IO.BinaryWriter temp_BinaryWriter51;
			temp_BinaryWriter51 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter51.Write((System.Single) attenuation);
			System.IO.BinaryWriter temp_BinaryWriter52;
			temp_BinaryWriter52 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter52.Write((System.Single) wait);
			System.IO.BinaryWriter temp_BinaryWriter53;
			temp_BinaryWriter53 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter53.Write((System.Single) delay);
			System.IO.BinaryWriter temp_BinaryWriter54;
			temp_BinaryWriter54 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter54.Write((System.Single) random);
			
			System.IO.BinaryWriter temp_BinaryWriter55;
			temp_BinaryWriter55 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter55.Write((System.Single) teleport_time);
			
			System.IO.BinaryWriter temp_BinaryWriter56;
			temp_BinaryWriter56 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter56.Write((System.Int32) watertype);
			System.IO.BinaryWriter temp_BinaryWriter57;
			temp_BinaryWriter57 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter57.Write((System.Int32) waterlevel);
			f.writeVector(move_origin);
			f.writeVector(move_angles);
			
			System.IO.BinaryWriter temp_BinaryWriter58;
			temp_BinaryWriter58 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter58.Write((System.Int32) light_level);
			System.IO.BinaryWriter temp_BinaryWriter59;
			temp_BinaryWriter59 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter59.Write((System.Int32) style);
			
			f.writeItem(item);
			
			moveinfo.write(f);
			monsterinfo.write(f);
			if (client == null)
			{
				System.IO.BinaryWriter temp_BinaryWriter60;
				temp_BinaryWriter60 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter60.Write((System.Int32) (- 1));
			}
			else
			{
				System.IO.BinaryWriter temp_BinaryWriter61;
				temp_BinaryWriter61 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter61.Write((System.Int32) client.index);
			}
			
			f.writeEdictRef(owner);
			
			// rst's checker :-)
			System.IO.BinaryWriter temp_BinaryWriter62;
			temp_BinaryWriter62 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter62.Write((System.Int32) 9876);
		}
		
		/// <summary>Reads the entity from the file. </summary>
		public virtual void  read(QuakeFile f)
		{
			s.read(f);
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			inuse = temp_BinaryReader.ReadBoolean();
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			linkcount = temp_BinaryReader2.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			num_clusters = temp_BinaryReader3.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			if (temp_BinaryReader4.ReadInt32() != 9999)
			{
				//UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
				SupportClass.WriteStackTrace(new System.Exception("wrong read pos!"), Console.Error);
			}
			
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			int len = temp_BinaryReader5.ReadInt32();
			
			if (len == - 1)
				clusternums = null;
			else
			{
				clusternums = new int[Defines.MAX_ENT_CLUSTERS];
				for (int n = 0; n < Defines.MAX_ENT_CLUSTERS; n++)
				{
					System.IO.BinaryReader temp_BinaryReader6;
					temp_BinaryReader6 = new System.IO.BinaryReader(f);
					temp_BinaryReader6.BaseStream.Position = f.Position;
					clusternums[n] = temp_BinaryReader6.ReadInt32();
				}
			}
			
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			headnode = temp_BinaryReader7.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			areanum = temp_BinaryReader8.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			areanum2 = temp_BinaryReader9.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			svflags = temp_BinaryReader10.ReadInt32();
			mins = f.readVector();
			maxs = f.readVector();
			absmin = f.readVector();
			absmax = f.readVector();
			size = f.readVector();
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			solid = temp_BinaryReader11.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader12;
			temp_BinaryReader12 = new System.IO.BinaryReader(f);
			temp_BinaryReader12.BaseStream.Position = f.Position;
			clipmask = temp_BinaryReader12.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader13;
			temp_BinaryReader13 = new System.IO.BinaryReader(f);
			temp_BinaryReader13.BaseStream.Position = f.Position;
			movetype = temp_BinaryReader13.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader14;
			temp_BinaryReader14 = new System.IO.BinaryReader(f);
			temp_BinaryReader14.BaseStream.Position = f.Position;
			flags = temp_BinaryReader14.ReadInt32();
			
			model = f.readString();
			System.IO.BinaryReader temp_BinaryReader15;
			temp_BinaryReader15 = new System.IO.BinaryReader(f);
			temp_BinaryReader15.BaseStream.Position = f.Position;
			freetime = temp_BinaryReader15.ReadSingle();
			message = f.readString();
			classname = f.readString();
			System.IO.BinaryReader temp_BinaryReader16;
			temp_BinaryReader16 = new System.IO.BinaryReader(f);
			temp_BinaryReader16.BaseStream.Position = f.Position;
			spawnflags = temp_BinaryReader16.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader17;
			temp_BinaryReader17 = new System.IO.BinaryReader(f);
			temp_BinaryReader17.BaseStream.Position = f.Position;
			timestamp = temp_BinaryReader17.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader18;
			temp_BinaryReader18 = new System.IO.BinaryReader(f);
			temp_BinaryReader18.BaseStream.Position = f.Position;
			angle = temp_BinaryReader18.ReadSingle();
			
			target = f.readString();
			targetname = f.readString();
			killtarget = f.readString();
			team = f.readString();
			pathtarget = f.readString();
			deathtarget = f.readString();
			combattarget = f.readString();
			
			target_ent = f.readEdictRef();
			
			System.IO.BinaryReader temp_BinaryReader19;
			temp_BinaryReader19 = new System.IO.BinaryReader(f);
			temp_BinaryReader19.BaseStream.Position = f.Position;
			speed = temp_BinaryReader19.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader20;
			temp_BinaryReader20 = new System.IO.BinaryReader(f);
			temp_BinaryReader20.BaseStream.Position = f.Position;
			accel = temp_BinaryReader20.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader21;
			temp_BinaryReader21 = new System.IO.BinaryReader(f);
			temp_BinaryReader21.BaseStream.Position = f.Position;
			decel = temp_BinaryReader21.ReadSingle();
			
			movedir = f.readVector();
			
			pos1 = f.readVector();
			pos2 = f.readVector();
			
			velocity = f.readVector();
			avelocity = f.readVector();
			
			System.IO.BinaryReader temp_BinaryReader22;
			temp_BinaryReader22 = new System.IO.BinaryReader(f);
			temp_BinaryReader22.BaseStream.Position = f.Position;
			mass = temp_BinaryReader22.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader23;
			temp_BinaryReader23 = new System.IO.BinaryReader(f);
			temp_BinaryReader23.BaseStream.Position = f.Position;
			air_finished = temp_BinaryReader23.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader24;
			temp_BinaryReader24 = new System.IO.BinaryReader(f);
			temp_BinaryReader24.BaseStream.Position = f.Position;
			gravity = temp_BinaryReader24.ReadSingle();
			
			goalentity = f.readEdictRef();
			movetarget = f.readEdictRef();
			
			System.IO.BinaryReader temp_BinaryReader25;
			temp_BinaryReader25 = new System.IO.BinaryReader(f);
			temp_BinaryReader25.BaseStream.Position = f.Position;
			yaw_speed = temp_BinaryReader25.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader26;
			temp_BinaryReader26 = new System.IO.BinaryReader(f);
			temp_BinaryReader26.BaseStream.Position = f.Position;
			ideal_yaw = temp_BinaryReader26.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader27;
			temp_BinaryReader27 = new System.IO.BinaryReader(f);
			temp_BinaryReader27.BaseStream.Position = f.Position;
			nextthink = temp_BinaryReader27.ReadSingle();
			
			prethink = (EntThinkAdapter) f.readAdapter();
			think = (EntThinkAdapter) f.readAdapter();
			blocked = (EntBlockedAdapter) f.readAdapter();
			
			touch = (EntTouchAdapter) f.readAdapter();
			use = (EntUseAdapter) f.readAdapter();
			pain = (EntPainAdapter) f.readAdapter();
			die = (EntDieAdapter) f.readAdapter();
			
			System.IO.BinaryReader temp_BinaryReader28;
			temp_BinaryReader28 = new System.IO.BinaryReader(f);
			temp_BinaryReader28.BaseStream.Position = f.Position;
			touch_debounce_time = temp_BinaryReader28.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader29;
			temp_BinaryReader29 = new System.IO.BinaryReader(f);
			temp_BinaryReader29.BaseStream.Position = f.Position;
			pain_debounce_time = temp_BinaryReader29.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader30;
			temp_BinaryReader30 = new System.IO.BinaryReader(f);
			temp_BinaryReader30.BaseStream.Position = f.Position;
			damage_debounce_time = temp_BinaryReader30.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader31;
			temp_BinaryReader31 = new System.IO.BinaryReader(f);
			temp_BinaryReader31.BaseStream.Position = f.Position;
			fly_sound_debounce_time = temp_BinaryReader31.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader32;
			temp_BinaryReader32 = new System.IO.BinaryReader(f);
			temp_BinaryReader32.BaseStream.Position = f.Position;
			last_move_time = temp_BinaryReader32.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader33;
			temp_BinaryReader33 = new System.IO.BinaryReader(f);
			temp_BinaryReader33.BaseStream.Position = f.Position;
			health = temp_BinaryReader33.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader34;
			temp_BinaryReader34 = new System.IO.BinaryReader(f);
			temp_BinaryReader34.BaseStream.Position = f.Position;
			max_health = temp_BinaryReader34.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader35;
			temp_BinaryReader35 = new System.IO.BinaryReader(f);
			temp_BinaryReader35.BaseStream.Position = f.Position;
			gib_health = temp_BinaryReader35.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader36;
			temp_BinaryReader36 = new System.IO.BinaryReader(f);
			temp_BinaryReader36.BaseStream.Position = f.Position;
			deadflag = temp_BinaryReader36.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader37;
			temp_BinaryReader37 = new System.IO.BinaryReader(f);
			temp_BinaryReader37.BaseStream.Position = f.Position;
			show_hostile = temp_BinaryReader37.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader38;
			temp_BinaryReader38 = new System.IO.BinaryReader(f);
			temp_BinaryReader38.BaseStream.Position = f.Position;
			powerarmor_time = temp_BinaryReader38.ReadSingle();
			
			map = f.readString();
			
			System.IO.BinaryReader temp_BinaryReader39;
			temp_BinaryReader39 = new System.IO.BinaryReader(f);
			temp_BinaryReader39.BaseStream.Position = f.Position;
			viewheight = temp_BinaryReader39.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader40;
			temp_BinaryReader40 = new System.IO.BinaryReader(f);
			temp_BinaryReader40.BaseStream.Position = f.Position;
			takedamage = temp_BinaryReader40.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader41;
			temp_BinaryReader41 = new System.IO.BinaryReader(f);
			temp_BinaryReader41.BaseStream.Position = f.Position;
			dmg = temp_BinaryReader41.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader42;
			temp_BinaryReader42 = new System.IO.BinaryReader(f);
			temp_BinaryReader42.BaseStream.Position = f.Position;
			radius_dmg = temp_BinaryReader42.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader43;
			temp_BinaryReader43 = new System.IO.BinaryReader(f);
			temp_BinaryReader43.BaseStream.Position = f.Position;
			dmg_radius = temp_BinaryReader43.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader44;
			temp_BinaryReader44 = new System.IO.BinaryReader(f);
			temp_BinaryReader44.BaseStream.Position = f.Position;
			sounds = temp_BinaryReader44.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader45;
			temp_BinaryReader45 = new System.IO.BinaryReader(f);
			temp_BinaryReader45.BaseStream.Position = f.Position;
			count = temp_BinaryReader45.ReadInt32();
			
			chain = f.readEdictRef();
			enemy = f.readEdictRef();
			
			oldenemy = f.readEdictRef();
			activator = f.readEdictRef();
			groundentity = f.readEdictRef();
			
			System.IO.BinaryReader temp_BinaryReader46;
			temp_BinaryReader46 = new System.IO.BinaryReader(f);
			temp_BinaryReader46.BaseStream.Position = f.Position;
			groundentity_linkcount = temp_BinaryReader46.ReadInt32();
			teamchain = f.readEdictRef();
			teammaster = f.readEdictRef();
			
			mynoise = f.readEdictRef();
			mynoise2 = f.readEdictRef();
			
			System.IO.BinaryReader temp_BinaryReader47;
			temp_BinaryReader47 = new System.IO.BinaryReader(f);
			temp_BinaryReader47.BaseStream.Position = f.Position;
			noise_index = temp_BinaryReader47.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader48;
			temp_BinaryReader48 = new System.IO.BinaryReader(f);
			temp_BinaryReader48.BaseStream.Position = f.Position;
			noise_index2 = temp_BinaryReader48.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader49;
			temp_BinaryReader49 = new System.IO.BinaryReader(f);
			temp_BinaryReader49.BaseStream.Position = f.Position;
			volume = temp_BinaryReader49.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader50;
			temp_BinaryReader50 = new System.IO.BinaryReader(f);
			temp_BinaryReader50.BaseStream.Position = f.Position;
			attenuation = temp_BinaryReader50.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader51;
			temp_BinaryReader51 = new System.IO.BinaryReader(f);
			temp_BinaryReader51.BaseStream.Position = f.Position;
			wait = temp_BinaryReader51.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader52;
			temp_BinaryReader52 = new System.IO.BinaryReader(f);
			temp_BinaryReader52.BaseStream.Position = f.Position;
			delay = temp_BinaryReader52.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader53;
			temp_BinaryReader53 = new System.IO.BinaryReader(f);
			temp_BinaryReader53.BaseStream.Position = f.Position;
			random = temp_BinaryReader53.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader54;
			temp_BinaryReader54 = new System.IO.BinaryReader(f);
			temp_BinaryReader54.BaseStream.Position = f.Position;
			teleport_time = temp_BinaryReader54.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader55;
			temp_BinaryReader55 = new System.IO.BinaryReader(f);
			temp_BinaryReader55.BaseStream.Position = f.Position;
			watertype = temp_BinaryReader55.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader56;
			temp_BinaryReader56 = new System.IO.BinaryReader(f);
			temp_BinaryReader56.BaseStream.Position = f.Position;
			waterlevel = temp_BinaryReader56.ReadInt32();
			move_origin = f.readVector();
			move_angles = f.readVector();
			
			System.IO.BinaryReader temp_BinaryReader57;
			temp_BinaryReader57 = new System.IO.BinaryReader(f);
			temp_BinaryReader57.BaseStream.Position = f.Position;
			light_level = temp_BinaryReader57.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader58;
			temp_BinaryReader58 = new System.IO.BinaryReader(f);
			temp_BinaryReader58.BaseStream.Position = f.Position;
			style = temp_BinaryReader58.ReadInt32();
			
			item = f.readItem();
			
			moveinfo.read(f);
			monsterinfo.read(f);
			
			System.IO.BinaryReader temp_BinaryReader59;
			temp_BinaryReader59 = new System.IO.BinaryReader(f);
			temp_BinaryReader59.BaseStream.Position = f.Position;
			int ndx = temp_BinaryReader59.ReadInt32();
			if (ndx == - 1)
				client = null;
			else
				client = GameBase.game.clients[ndx];
			
			owner = f.readEdictRef();
			
			// rst's checker :-)
			System.IO.BinaryReader temp_BinaryReader60;
			temp_BinaryReader60 = new System.IO.BinaryReader(f);
			temp_BinaryReader60.BaseStream.Position = f.Position;
			if (temp_BinaryReader60.ReadInt32() != 9876)
				System.Console.Error.WriteLine("ent load check failed for num " + index);
		}
	}
}